﻿@using Gardener.Core.Audit.Dtos
@using Gardener.Core.Audit.Resources
@if (AuditEntitys != null && AuditEntitys.Any())
{
    <Collapse DefaultActiveKey="@(new[] { AuditEntitys.Select(x=>x.Id.ToString()).FirstOrDefault()})" Accordion Style="max-height:85Vh;overflow-y:scroll;">
        @foreach (AuditEntityDto item in AuditEntitys)
        {
        var title = $"[{item.OperaterName} {Localizer[nameof(SharedLocalResource.On)]} {item.CreatedTime.ToString("yyyy-MM-dd HH:mm:ss")} {Localizer[EnumHelper.GetEnumDescriptionOrName(item.OperationType)??item.OperationType.ToString()]}  {item.Name}（{item.DataId}）]";
        <Panel Header="@title" Key="@item.Id.ToString()" OnActiveChange="b=>{listBindValue[item.Id]=b;}">
                @if (listBindValue[item.Id])
                {
                    <AuditPropertieList OperationType="item.OperationType" AuditProperties="item.AuditProperties" Localizer="Localizer"></AuditPropertieList>
                }
            </Panel>
        }
    </Collapse>
}
else
{
    <Empty Simple />
}
@code {
    /// <summary>
    /// 数据审计
    /// </summary>
    [Parameter]
    public ICollection<AuditEntityDto>? AuditEntitys { get; set; }
    /// <summary>
    /// 本地化
    /// </summary>
    [Parameter]
    [System.ComponentModel.DataAnnotations.Required]
    public ILocalizationLocalizer Localizer { get; set; } = null!;
    //未展开的不渲染，减少性能开销
    private ClientListBindValue<Guid, bool> listBindValue = new ClientListBindValue<Guid,bool>(false);
}
